<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>游记明细</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css">
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/travelContent.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <script src="/js/common.js"></script>
    <link rel="stylesheet" href="js/plugins/dialog2/dialog.css">
    <script src="js/plugins/dialog2/dialog.min.js"></script>
    <script>
        $(function () {
            //获取共享过来的user字符串
            var userStr= sessionStorage.getItem("user")
            //console.log(userStr);
            //解析这个字符串改为user对象
            var user=JSON.parse(userStr);

            var params = getParams();
            var authorId=0;
            var userStr = sessionStorage.getItem("user")
            var user = JSON.parse(userStr);
            if (params.id) {
                $.get("/travel/" + params.id, function (data) {
                    authorId=data.author.id
                    //jrender回显
                        $(".travels").renderValues(data)
                    var html="";
                    if (data.person==1){
                        html="一个人旅行"
                    }else if(data.person==2){
                        html="和父母"
                    }else if(data.person==3){
                        html="和朋友"
                    }else if(data.person==4){
                        html="和同时"
                    }else if(data.person==5){
                        html="和爱人"
                    }else if(data.person==6){
                        html="和其他"
                    }
                    $("#person").html(html)
                    $.get("/users/"+data.author.id,function (item) {

                        //根据状态来显示按钮
                        if(user.id == data.author.id){
                            $("#followBtn").attr("style","display: none");
                            $("#cancelBtn").attr("style","display: none");
                        }else{
                            if(item.state == 1){
                                $("#followBtn").attr("style","display: none");
                            } else if (item.state == 0){
                                $("#cancelBtn").attr("style","display: none");
                            }
                        }
                    })

                    //给关注绑定点击事件
                    $("#followBtn").click(function () {
                        $.ajax({
                            url: "/users/"+data.author.id+"/author",
                            type: "PUT",
                            success: function () {
                                window.location.reload();
                            }
                        })
                    })

                    //给取关绑定点击事件
                    $("#cancelBtn").click(function () {
                        $.ajax({
                            url: "/users/"+data.author.id+"/author",
                            type: "PUT",
                            success: function () {
                                window.location.reload();
                            }
                        })
                    });

                    //获得游记总数
                    $.get("/travel/" + data.author.id +"/count",function (data) {
                        $(".travels").renderValues({count:data});
                    })


                    //查询是否已经被点赞
                    var status=1;
                    $.get("messages/like", {authorId: authorId, "liker.id": user.id,state: 1,bindId:params.id},function (data) {
                        console.log(data);
                        if (!data){
                            $("#likeBtn").css({"color": "red"});
                            status=2;
                        }
                    })



                    //设置状态,状态为2就不能发送指令,点赞事件
                    $("#likeBtn").click(function () {
                        if (status == 1) {
                        $(this).css({"color": "red"})
                            $.post("/messages/like", {authorId: authorId, "liker.id": user.id, state: 1,bindId:params.id})
                            status = 2;
                        }else {
                            $(this).css({"color": "black"})
                            $.ajax({
                                url: "/messages/like",
                                data:{authorId: authorId, "liker.id": user.id, state: 1,bindId:params.id},
                                type: "DELETE",
                                success: function () {
                                }
                            })
                            //删除完了,又可以点赞
                            status = 1;
                        }
                    })

                })


            }



        })


    </script>

</head>
<body>
<div class="search-head">
    <div class="row nav-search">
        <div class="col">
            <a href="javascript:history.go(-1);">
                <span><i class="fa fa-chevron-left"></i></span>
            </a>
        </div>
        <div class="col">
        </div>
    </div>
</div>

<div class="travels">
    <img class="cover" render-src="coverUrl">
    <div class="container">
        <h6 class="title" render-html="title"></h6>
        <small>
            <span render-html="releaseTime"></span>
            浏览 <span> 0</span>
            回复 <span> 0</span>
        </small>
        <div class="row">
            <div class="col-2 img">
                <img class="rounded-circle" render-src="coverUrl">
            </div>
            <div class="col-6 mine">
                <small>
                    <span render-html="author.nickName"></span>
                    <button class="btn" id="followBtn">关注</button>
                    <button class="btn" id="cancelBtn">已关注</button>
                    <br>
                    <span render-html="count">0 </span>篇游记
                    <span render-html="author.fans">0 </span>粉丝
                </small>
            </div>
            <div class="attention col">
                <span class="addr" render-html="place.name"></span>
            </div>
        </div>
    </div>
    ,
    <div class="container">
        <fieldset>
            <legend>我的出行信息</legend>
            <div class="d-flex">
                <div class="p-2  flex-fill">
                    <i class="fa fa-calendar"></i> 出发时间 <span render-html="travelTime"></span>
                </div>
                <div class="p-2  flex-fill"><i class="fa fa-money"></i> 人均费用
                    <span render-html="perExpends"></span></div>
            </div>
            <div class="d-flex">
                <div class="p-2  flex-fill">
                    <i class="fa fa-user-circle"></i> 人物
                    <span id="person"></span>
                </div>
                <div class="p-2  flex-fill"><i class="fa fa-clock-o"></i> 出行天数
                    <span render-html="days">1</span>
                </div>
            </div>
        </fieldset>

        <div class="content" render-html="travelContent.content">

        </div>
    </div>

    <hr>

    <div class="container d-flex">
        <div class="p-2  flex-fill">
            <i class="fa fa-thumbs-o-up"  id="likeBtn"> </i>
        </div>
        <div class="p-2  flex-fill"><i class="fa  fa-commenting-o" id="commentBtn"> </i>
        </div>
        <div class="p-2  flex-fill" style=""><i class="fa fa-star-o" id="collectBtn"> </i>
        </div>
    </div>
</div>

<HR style="FILTER: progid:DXImageTransform.Microsoft.Shadow(color:#987cb9,direction:145,strength:15)" width="80%"
    color=#987cb9 SIZE=1>

<div class="tab-content " id="pills-tabContent">
    <div id="comment">
        <div render-loop="list">
            <div class="container row comment">
                <div class="col-2 comment-head">
                    <img class="rounded-circle"
                         render-src="list.user.headImgUrl" width="35px" height="35px">
                </div>
                <div class="col comment-right">
                    <p class="authorName"><span render-html="list.user.nickName">dafei</span></p>
                    <span class="comment-date" render-html="list.createTime">2018-07-19</span>
                    <div class="comment-content">
                        <a role="button" href="/mine/askAnswer.html?id=">
                            <p render-html="list.content">很好我觉得很好我觉得很好我觉得很好</p>
                        </a>
                    </div>
                </div>
                --------------------------------------->
            </div>
        </div>
    </div>
</div>
<!--begin................................................................-->
<script>
    //收藏
    $(function () {
        var collect = 0;
        var user = sessionStorage.getItem("user");
        //点击收藏
        $("#collectBtn").click(function () {
            if (user) {
                if (collect == 0) {
                    $("#collectBtn").css({"color": "red"});
                    collect = 1;
                    $.post("/collect", {travelId: getParams().id});
                } else if (collect == 1) {
                    $("#collectBtn").attr("style", "");
                    collect = 0;
                    $.post("/collect", {travelId: getParams().id});
                }
            } else {
                location.href = "/login.html";
            }
        });
        if(user){
            //发送请求进行收藏回显
            $.get("/collect/select", {travelId: getParams().id}, function (data) {
                if (data.success) {
                    $("#collectBtn").css({"color": "red"});
                    collect=1;
                } else {
                    $("#collectBtn").attr("style", "");
                }
            })
        }
    })
</script>
<!--end..................................................................-->
</body>
<!--begin................................................................-->
<script>
    $(function () {
        //回显评论
        $.get("/collect/listComment",{travelId:getParams().id},function (date) {
            $("#comment").renderValues({list:date});
        });

        //发表评论
        $("#commentBtn").click(function () {
            if(sessionStorage.getItem("user")){
                location.href="/mine/collectComment.html?travelId="+getParams().id;
            }else {
                $(document).dialog({
                    type: 'notice',
                    infoText: '请先登录',
                    autoClose: 2000,
                    position: 'bottom'  // center: 居中; bottom: 底部
                });
            }
        });
    })
</script>
<!--end..................................................................-->
</html>